///<reference path="../../node_modules/rxjs/Observable.d.ts"/>
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import {url_dish as api_url} from "../config";
import {Dish} from "../models/Dish";

import {Observable} from "rxjs/Observable";
import 'rxjs/add/operator/map';

/*
 Generated class for the DishProvider provider.

 See https://angular.io/docs/ts/latest/guide/dependency-injection.html
 for more info on providers and Angular 2 DI.
 */

@Injectable()
export class DishProvider {
  constructor(public http: Http) {
    console.log('Hello DishProvider Provider');
  }

  getDishes(page = 1, category?: number,keywords?:string): Observable<any> {
    let url = api_url + "?page=" + page;
    if(category!=null || keywords !=null || category > 0 || keywords!='')
      url = url +"&search=";
    if (category != null)
      url = url + "Dish_Category_ID:" + category;
    if (category!=null && keywords !=null){
      url=url+';';
    }
    if(keywords!=null)
      url = url +"Dish_Name:"+keywords;
    console.log(url);
    return this.http.get(url)
      .map(response => response.json().data as Dish[]);
  }

  getDishesCart(): Observable<any> {
    let url = api_url + "_cate";
    console.log(url);
    return this.http.get(url)
      .map(response => response.json().data );
  }


}
